from rest_framework import serializers

from apps.headlines.models import Article
from apps.questions.models import Reply
from apps.questions.serializers import LabelModelSerializer, QuestionsModelSerializer
from apps.recruits.models import Enterprise
from apps.recruits.serializers import Enterpriseserializer
from apps.users.models import User


# 我回答的问题
class MyreplyforquestionSerializer(serializers.ModelSerializer):
    problem = serializers.PrimaryKeyRelatedField(read_only=True)

    class Meta:
        model = Reply
        fields = '__all__'


class collectedArticleSerializer(serializers.ModelSerializer):
    user = serializers.StringRelatedField()
    collected_users = serializers.StringRelatedField(many=True)
    class Meta:
        model = Article
        fields = '__all__'


class CenterEnterpisesSerializer(serializers.ModelSerializer):
    recruits = serializers.PrimaryKeyRelatedField(read_only=True,many=True)

    class Meta:
        model = Enterprise
        fields = ['id','name','labels','logo','recruits','summary']


class CenterSerializer(serializers.ModelSerializer):
    labels = LabelModelSerializer(read_only=True, many=True)
    questions = QuestionsModelSerializer(many=True, read_only=True)
    enterpises = CenterEnterpisesSerializer(many=True, read_only=True)
    id = serializers.IntegerField(read_only=True)
    class Meta:
        model = User
        fields = ['id', 'username', 'mobile', 'realname', 'birthday', 'sex', 'avatar', 'website', 'email', 'city',
                  'address', 'labels', 'enterpises', 'questions']

class UpdatePasswordSerializers(serializers.ModelSerializer):
    password = serializers.CharField(write_only=True)

    class Meta:
        model = User
        fields = ['password']


class ImageSerializers(serializers.ModelSerializer):
    class Meta:
        model = User
        fields = ['avatar']
